package com.backend.modules.system.repository;

import com.backend.modules.system.entity.SysUser;
import java.util.List;
import java.util.Set;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.Optional;

public interface SysUserRepository extends JpaRepository<SysUser, Long>, JpaSpecificationExecutor<SysUser> {
    
    Optional<SysUser> findByUsername(String username);
    
    boolean existsByUsername(String username);

    boolean existsByUserCode(String userCode);

    @EntityGraph(attributePaths = {"department"})
    Page<SysUser> findAll(Specification<SysUser> spec, Pageable pageable);



    Integer countByUserType(int userType);

    /**
     * 根据部门ID和用户类型查询用户列表
     */
    List<SysUser> findByDepartmentIdAndUserType(Long departmentId, Integer userType);

}